package com.sport.setting.repository;

import com.sport.model.application.pojos.SportMemberEnroll;
import com.sport.model.program.vos.SheetThreeVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Component
@Transactional
public class SportProgramRepository {
    @Autowired
    SportMemberEnrollRepository sportMemberEnrollRepository;

    public List<SheetThreeVO> sheetThreeData(){
        //获得组别及对应参赛单位
        Map<String, List<String>> gradeAndUnitMap = sportMemberEnrollRepository.showGradeAndUnit();
        List<SheetThreeVO> sheetThreeVOS=new ArrayList<>();
        for (Map.Entry<String, List<String>> stringListEntry : gradeAndUnitMap.entrySet()) {
            SheetThreeVO sheetThreeVO=new SheetThreeVO();
            sheetThreeVO.setGrade(stringListEntry.getKey());
            List<String> units = stringListEntry.getValue();
            for (String unit : units) {
                //查询对应的人员
                //男子
                List<SportMemberEnroll> maleList = sportMemberEnrollRepository.getMemberList(unit, 1);
                List<SportMemberEnroll> femaleList = sportMemberEnrollRepository.getMemberList(unit, 2);
                sheetThreeVO.setUnit(unit);
                sheetThreeVO.setMaleList(maleList);
                sheetThreeVO.setFemaleList(femaleList);
                sheetThreeVOS.add(sheetThreeVO);
            }

        }
        return sheetThreeVOS;
    }
}
